<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>资管支付表代偿管理</title>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 80px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div>
        <div id="pageInTab" class="pageInTab">
            <div tabid="repaySettle" title="资管代偿" lselected="true">
                <div class="searchArea">
                    <form id="searchBar">
                        <div class="fieldset1 clearFix">
                            <div class="fieldBox">
                                <div class="label">资方支付表号</div>
                                <div class="field">
                                    <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">第三方机构</div>
                                <div class="field">
                                    <input name="insCode" id="insCode" data-value="" placeholder="请选择" ltype="combobox">
                                </div>
                            </div>
                            <div class="formBtns notRight">
                                <span id="searchBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_1"></i>查询</span>
                                <span id="clearBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_19"></i>清空</span>
                                <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                            </div>
                        </div>
                    </form>
                </div>
                <div id="ligergrid" class="sq-grid"></div>
            </div>
            <div tabid="repaySettleLog" title="代偿记录">
                <iframe frameborder="0" name="repaySettleLog" id="repaySettleLog" src=""></iframe>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var grid = null, menu = null;
    var pageInApp = {};
    var loadedTabs = [];
    $(function () {
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onAfterSelectTabItem: function (tabid) {
                if (loadedTabs.indexOf(tabid) < 0) {
                    loadedTabs.push(tabid);
                    switch (tabid) {
                        case "repaySettleLog":
                            pageInTab.setTabItemSrc(tabid, "<%=path%>/repay/insCstRepaySettle/toRepayLogListPage.do");
                            break;
                    }
                }
                SetIframe_height();
            }
        });

        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });

        grid = $("#ligergrid").ligerGrid({
            url: '<%=path%>/repay/insCstRepaySettle/initList.do?isEnable=1&paySchTypCd=ZF',
            method: 'get',
            columns: [
                { display: '合同号', name: 'lsCntNo', minWidth: 150 ,align:'left'},
                { display: '支付表号', name: 'paySchNo', minWidth: 200,align:'left',},
                { display: '承租人名称', name: 'cstNm', minWidth: 80,align:'left'},
                { display: '第三方机构', name: 'insNm', minWidth: 80,align:'left'},
                { display: '起租日', name: 'lsDt', minWidth: 80,align:'left',render:renderDate},
                { display: '操作', name: '操作', minWidth: 200,align:'left',
                    render: function (rowdata, rowindex, value, column) {
                        var h = '';
                        var insCode = rowdata.insCode;
                        if (insCode == 'zgcbank' || insCode == 'zbbank' || insCode == 'ybccbank') {
                            h='<a class="sq-button-hasicon" href="javascript:repayOrSettle(';
                            h+="'"+rowdata.id+"',";
                            h+="'"+rowdata.paySchNo+"',";
                            h+="'"+rowdata.insCode+"',";
                            h+="'"+rowdata.prjId+"',";
                            h+="'"+rowdata.insId+"',";
                            h+="'repay'";
                            h+=')"><i class=\"sqBtnIco_4\"></i>'+'代偿'+'</a>'
                        }
                        h+='<a class="sq-button-hasicon" href="javascript:repayOrSettle(';
                        h+="'"+rowdata.id+"',";
                        h+="'"+rowdata.paySchNo+"',";
                        h+="'"+rowdata.insCode+"',";
                        h+="'"+rowdata.prjId+"',";
                        h+="'"+rowdata.insId+"',";
                        h+="'settle'";
                        h+=')"><i class=\"sqBtnIco_4\"></i>'+'提前结清'+'</a>'
                        return h;
                    }
                },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
        grid.setHeight(100);

        $("#searchBar").ligerForm();

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });
        
        var callback = function () {
            grid.reload();
        };

        $("#insCode").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        liger.get("insCode").setData(${insCdList});
    });

    var onOk = function (item, Dialog) {
        if (Dialog.onOk) Dialog.onOk();
    };
    var onCancel = function (item, Dialog) {
        if (Dialog.onCancel) Dialog.onCancel();
    };
    var onCal = function (item, Dialog) {
        if (Dialog.onCal) Dialog.onCal();
    };

    function repayOrSettle(id,paySchNo,insCode,prjId,insId,type){
        var temp = "贷款还款";
        if(type == 'settle'){
            temp = "提前还款"
        }
        if(insCode == 'zbbank'&& type == 'settle' ){
            $.ligerDialog.SQopen({
                width: 550,
                height: 400,
                title: temp,
                url: '<%=path%>/repay/insCstRepaySettle/toAddPage.do?id='+id+'&paySchNo='+paySchNo+'&prjId='+prjId+'&insId='+insId+'&insCode='+insCode+'&type='+type,
                buttons: [
                    {
                        text: temp, onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
                    },
                    {
                        text: "提前还款试算", onclick: onCal, type: 'ok', cls: 'l-dialog-btn-ok'
                    },
                    {
                        text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
                    }
                ]
            });
        }else{
            $.ligerDialog.SQopen({
                width: 550,
                height: 400,
                title: temp,
                url: '<%=path%>/repay/insCstRepaySettle/toAddPage.do?id='+id+'&paySchNo='+paySchNo+'&prjId='+prjId+'&insId='+insId+'&insCode='+insCode+'&type='+type,
                buttons: [
                    {
                        text: temp, onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
                    },
                    {
                        text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
                    }
                ]
            });
        }

    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
</script>

</body>
</html>
